#include <QtPlugin>

#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QSpinBox>
#include <QDoubleSpinBox>
#include <QWidget>
#include <QPushButton>
#include <QLabel>
#include <QCheckBox>
#include <QComboBox>

#include <opencv/cv.h>
#include <opencv/highgui.h>

#include "CVMatchingAlgos.h"

#include "QCVModuleInterface.h"
#include "QCVModuleHandlerInterface.h"

#include "QViewSelector.h"

#ifndef MODULE_TRACKING_KALMAN
#define MODULE_TRACKING_KALMAN

class ModuleTracking:public QObject,QCVModuleInterface
{
  Q_OBJECT
	Q_INTERFACES(QCVModuleInterface)
	
	public:
		void init(QCVModuleHandlerInterface * parent);
		void free();

		cv::Mat & process();
		void setInput(int n,const cv::Mat & m);

		QWidget* widget();
		QString getName();
		int nbInputs();
		QString getParams();
    bool setParams(QString params);
		QString help(int id);		
	
		QCVModuleInterface * clone();

	private slots:
		void s_forceFirstPosition();
		void s_displayLinks(int state);
		void s_displayKeysPoints(int state);

	private:  
		QLabel * l_flann;
		QLabel * l_kalman;
		QLabel * l_affichage;
		
		cv::KalmanFilter KF;
		bool isKFMode1Init,isKFMode2Init;

		QSpinBox * sb_marges;

    QWidget * win;
    QHBoxLayout * layout;
		QPushButton * forceFirstPosition;		
		QSpinBox * sb_precision;
		QDoubleSpinBox * sb_distance_max;
		
		QComboBox * mode;

		QCheckBox * cb_display_keyspoints;
		QCheckBox * cb_display_links;		

		cv::Mat_<float> mesured_state;
		cv::Mat_<float> predicted_state;

		cv::Mat_<float> currentDescriptors,previousDescriptors;
		cv::Mat_<float> currentKeysPoints,previousKeysPoints;
		cv::Mat_<int> linkedKeysPoints;

		cv::Mat currentFrame;

		QViewSelector * view_selector;

		QCVModuleHandlerInterface * parent;
};

#endif
